//
//  NSNumber+TYHelper.m
//  TYFoundation
//
//  Created by 郭艺伟 on 2019/2/28.
//

#import "NSNumber+TYHelper.h"
#import <CoreGraphics/CoreGraphics.h>

@implementation NSNumber (TYHelper)


//转换文件大小显示样式
- (NSString *)ty_fileSizeString {
    double fileSizeT = [self doubleValue];
    
    if (fileSizeT <= 0.f) {
        return @"0B";
    }
    if (fileSizeT < 1024.f) {
        return [NSString stringWithFormat:@"%.1fB", fileSizeT];
    }
    
    CGFloat size = fileSizeT/1024.0;
    size = (int)((size * 10) + 0.5) /10.0;  //四舍五入（暂时保留小数点一位）
    if (size < 1024) {
        return [NSString stringWithFormat:@"%.1fKB", size];
    }
    
    size = fileSizeT/(1024 * 1024.0);
    size = ((int)((size * 10) + 0.5))/10.0;
    return [NSString stringWithFormat:@"%.1fMB", size];
}

@end
